var PrintInWarehouse = function () {
  var template = /* html */ `
    <div class="print-warehouse" v-loading.fullscreen.lock="loading">
      <div style="height:40px">
        <el-button type="primary" size="small" @click="print">打印</el-button>
        <config-button v-if="tableColumns!==null" :config.sync="pageConfig" :table-columns="tableColumns">出库单设置</config-button>
      </div>
      <div class="print-warehouse-div print-area" style="text-align:center" v-if="user!==null&&pageConfig.tableColumns!==undefined">
        <div class="print-warehouse-content" :style="[pageSize]">
          <div ref="printArea">
            <div style="text-align:center" :style="[textSize.titleSize]">{{user.company}}入库单</div>
            <div class="print-warehouse-header" :style="[textSize.otherSize]">
              <div class="clearfix">
                <div class="print-warehouse-form-item" style="min-height:20px;width:calc(100% - 14em)">
                  <div class="label" style="width:5em">入货单号</div>
                  <div class="text">
                    <input v-if="mode==='edit'" v-model="printOrderNo" style="width:12em;" :style="[textSize.otherSize]" class="print-warehouse-input"
                      maxlength="20" placeholder="请输入入货单号">
                    <span v-else>{{printOrderNo}}</span>
                  </div>
                </div>
                <div class="print-warehouse-form-item" style="width:14em">
                  <div class="label" style="width:4em">入货日期</div>
                  <div class="text">
                    <el-date-picker v-if="mode==='edit'" class="print-warehouse-time-input" size="mini" v-model="warehouseInfo.deliverTime"
                      format="yyyy年M月d日" value-format="timestamp" style="width:10em;" :editable="false" :clearable="false" :style="[textSize.otherSize]">
                    </el-date-picker>
                    <span v-else>{{moment(warehouseInfo.deliverTime).format('YYYY年M月D日')}}</span>
                  </div>
                </div>
              </div>
            </div>
            <div class="print-warehouse-table">
              <table cellspacing="0" cellpadding="0" :style="[textSize.tableSize]">
                <colgroup>
                  <template v-for="tableColumn in pageConfig.tableColumns">
                    <col :key="'col_'+tableColumn.id" :style="{width:tableColumn.width+'px'}">
                  </template>
                </colgroup>
                <tr v-if="pageConfig.showTableHead">
                  <th v-for="tableColumn in pageConfig.tableColumns" :key="'head_'+tableColumn.id">
                    <span>{{tableColumn.label}}</span>
                    <div v-if="tableColumn.hasSort&&mode==='edit'" class="sort-caret" :class="[tableColumn.sortType]">
                      <div class="sort-index">{{getSortIndex(tableColumn)}}</div>
                      <i class="ascending" @click="toOrderData(tableColumn,'ascending')"></i>
                      <i class="descending" @click="toOrderData(tableColumn,'descending')"></i>
                    </div>
                  </th>
                </tr>
                <template v-for="(order,index) in printOrders">
                  <tr :key="'oreder_'+index">
                    <td v-for="(tableColumn,colIndex) in pageConfig.tableColumns" :key="'data_'+tableColumn.id">
                      <div v-if="!tableColumn.config.edit" style="height:100%;" :style="[getAlignStyle(tableColumn)]">
                        {{getTableData(order,tableColumn,index)}}
                      </div>
                      <div v-else>
                        <show-textarea class="orderTextarea" v-model="order[tableColumn.config.field]" :autosize="true">
                        </show-textarea>
                      </div>
                    </td>
                  </tr>
                </template>
                <tr>
                  <td v-for="(tableColumn,colIndex) in pageConfig.tableColumns" :key="'stat_'+tableColumn.id">
                    {{getStatData(tableColumn,colIndex)}}
                  </td>
                </tr>
              </table>
            </div>
            <div v-if="clauseContent!==''" style="margin-top:5px;text-align:left;" :style="[textSize.otherSize]">
              <div class="vue-rich-editor" v-html="clauseContent"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  `;

  return {
    mixins: [printWarehouseInoutTemplMixin('warehouseInOrder', 'warehouseInOrderColumns')],

    methods: {
      print: function () {
        if (this.printOrderNo === '') {
          this.$alert('请输入出货单号', '信息');
          return;
        }

        this.toPrintOrder('inWarehouseOrder');
      },

      getStatData: function (tableColumn, colIndex) {
        if (colIndex === 0) {
          return '合计';
        }

        var field = tableColumn.config.field;
        if (['totalPrice', 'count'].indexOf(field) === -1) {
          return '';
        }

        var printOrders = this.printOrders;
        if (field === 'count') {
          var unitOrdrs = _.uniqBy(printOrders, 'inOutUnit');
          if (unitOrdrs.length !== 1) {
            return '';
          }
        }
        var sumData = _.sumBy(printOrders, field);
        sumData = _.round(sumData, 2);
        return sumData;
      }
    },

    template: template
  };
}();
